'''
### 控制语句和现实逻辑表达
'''

'''
### 单分支选择结构-条件表达式详解
'''
# num = input("请输入一个数字：")
# if int(num) < 10:
#     print("小于10的数：" + str(num))
# if 3:
#     print("ok!")
# if "false":
#     print("false")
# a = 4
# if 2 < a < 5:
#     print("2 < a < 5")

'''
### 双分支选择结构-三元运算符的使用详解
'''
# num = input("输入一个数字:")
# if int(num) < 10:
#     print(str(num) + "<10")
# else:
#     print(str(num) + ">10")
# print(num + "<10" if(int(num) < 10) else str(num) + ">10")

'''
### 多分支选择结构
'''
# score = input("输入学生分数：")
# grade = ''
# if 0 <= int(score) < 60:
#     grade = "不及格"
# elif int(score) < 80:  # 60<=score<=80  多分支之间具有逻辑关系
#     grade = "及格"
# elif int(score) < 90:
#     grade = "良好"
# elif int(score) <= 100:
#     grade = "优秀"
# else:
#     grade = "成绩输入错误"
# print("分数是{0}，等级是{1}".format(score, grade))

'''
### 选择结构的嵌套
'''
# score = int(input("输入一个0-100之间的数字："))
# grade = ''
# if score > 100 or score < 0:
#     score = int(input("输入错误，请重新输入0-100之间的数字："))
# else:
#     if score >= 90:
#         grade = 'A'
#     elif score >= 80:
#         grade = 'B'
#     elif score >= 70:
#         grade = 'C'
#     elif score >= 60:
#         grade = 'D'
#     else:
#         grade = 'E'
# print("分数是{0}，等级是{1}".format(score, grade))

# 更少的代码方法
# score = int(input("输入一个0-100之间的数字："))
# grade = 'ABCDE'
# if score > 100 or score < 0:
#     score = int(input("输入错误，请重新输入0-100之间的数字："))
# else:
#     num = score // 10
#     if num < 6:
#         num = 5
#     print("分数是{0}，等级是{1}".format(score, grade[9-num]))

'''
### while循环结构-死循环处理
'''

'''
### for循环结构-遍历各种可迭代对象-range对象
'''
# for x in (20, 30, 50):
#     print(x*3)
#
# for temp in "weqwewe":
#     print(temp)
# d = {"name": "haha", "age": 12, "sex": "male"}
# for x in d:    # 遍历字典所以key
#     print(x)
# for x in d.keys():    # 遍历字典所有的key
#     print(x)
# for x in d.values():    # 遍历字典所有的value
#     print(x)
# for x in d.items():    # 遍历字典所有键值对
#     print(x)
# for x in range(3, 10, 2):  # start=3 end=10 step=2 包头不包尾
#     print(x, end='\t')
# sum_all = 0
# sum_even = 0
# sum_odd = 0
# for x in range(101):
#     sum_all += x
#     if x % 2 == 0:
#         sum_even += x
#     else:
#         sum_odd += x
# print("1-100累加和{0}，奇数累加和{1}，偶数累加和{2}".format(sum_all, sum_odd, sum_even))

'''
### 嵌套循环
'''
# for x in range(5):
#     for y in range(5):
#         print(x, end="\t")
#     print()
'''
### 嵌套循环练习-九九乘法表-打印表格数据
'''
# for m in range(1, 10):
#     for n in range(1, m+1):
#         print("{0}*{1}={2}".format(m, n, m*n), end="\t")
#     print()
# r1 = dict(name="hycs", age=18, salary=10000, city="shanghai")
# r2 = dict(name="sdaw", age=28, salary=20000, city="beijing")
# r3 = dict(name="e1qe", age=38, salary=30000, city="nanjing")
# tb = [r1, r2, r3]
# for x in tb:
#     if x.get("salary")>15000:
#         print(x)
'''
### break语句
'''

'''
### continue语句
'''
# empNum = 0
# salarySum = 0
# salarys = []
# while True:
#     s = input("请输入员工薪资（按Q或q退出）")
#     if s.upper() == "Q":
#         break
#     if float(s) < 0:
#         print("无效录入，请重新录入")
#         continue
#     print("录入成功")
#     empNum += 1
#     salarySum += float(s)
#     salarys.append(float(s))
# print("员工数", format(empNum))
# print("录入薪资：", salarys)
# print("总薪资：", salarySum)
# print("平均薪资", salarySum / empNum)
'''
### 循环中的else子句
'''
# salarySum = 0
# salarys = []
# for i in range(4):
#     s = input("请输入员工薪资（按Q或q退出）")
#     if s.upper() == "Q":
#         break
#     if float(s) < 0:
#         print("无效录入，请重新录入")
#         continue
#     print("录入成功")
#     salarySum += float(s)
#     salarys.append(float(s))
# else:
#     print("全部录入成功")
#
# print("录入薪资：", salarys)
# print("总薪资：", salarySum)
# print("平均薪资", salarySum / 4)
'''
### 循环代码优化技巧
'''

'''
### zip()并行送代多个序列
'''
# names = ("haohao", "hehe", "huaiyue")
# ages = (18, 19, 20)
# jobs = ("IT", "TEACHER", "POLICE")
# # 使用zip并行迭代多个序列
# for name, age, job in zip(names, ages, jobs):
#     print("{0}--{1}--{2}".format(name, age, job))
# # 不使用zip也可以并使迭代多个序列
# for i in range(min(len(names), len(ages), len(jobs))):
#     print("{0}--{1}--{2}".format(names[i], ages[i], jobs[i]))
'''
### 推导式创建序列-列表推导式-字典推导式-集合推导式-生成器推导式
'''
# a = [x for x in range(1, 10) if x % 2 == 0]
# print(a)
#
# cells = [(row, column) for row, column in zip(range(1, 10), range(101, 110))]
# print(cells)

# my_text = 'i love python, me too'
# char_count = {c: my_text.count(c) for c in my_text}
# print(char_count)
'''
### 总和练习-绘制不同颜色的同心圆-绘制棋盘
'''
import turtle

p = turtle.Pen()  # 画笔对象

radius = [x * 10 for x in range(1, 11)]
my_color = ["red", "yellow", "black", "green"]
p.width(4)
for r, i in zip(radius, range(len(radius))):
    p.penup()
    p.goto(0, -r)
    p.pendown()
    p.color(my_color[i % len(my_color)])
    p.circle(r)

turtle.done()  # 程序执行完毕，窗口还在
